package com.yehui.jdk.jdk11;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author 业徽
 * @date 2021/8/23
 */
public class StreamDemo {

    public static void main(String[] args) {
        final List<String> list = List.of("a", "b", "c", "f", "fdfd", "dd", "dfsagfda", "dfdfd");
        final String takeWhile = list.stream()
                // 查找符合条件的，知道第一个不符合的就停止
                .takeWhile(s -> s.length() < 4)
                .collect(Collectors.joining(","));
        System.out.println("takeWhile: " + takeWhile);

        final String dropWhile = list.stream()
                // 丢弃符合条件的，知道第一个不符合的就停止
                .dropWhile(s -> s.length() < 4)
                .collect(Collectors.joining(","));
        System.out.println("dropWhile: " + dropWhile);

        final String ofNullable = Stream.ofNullable("aaaa").collect(Collectors.joining(","));
        System.out.println("ofNullable: " + ofNullable);
    }

}
